//
//  SearchResultColCell.swift
//  WalkNovel
//
//  Created by Kevin on 2023/7/6.
//

import UIKit

class SearchResultColCell: UICollectionViewCell {
    
    lazy var bookImage: UIImageView = {
        let image = UIImageView(image: UIImage(named: "placeholder_cover_ver"))
        image.contentMode = .scaleAspectFill
        image.wn_cornerWithBorder(2)
        image.clipsToBounds = true
        return image
    }()
    
    lazy var disLabel: UILabel = {
        let label = UILabel()
        label.font = .wn_font(name: .bold, size: 9)
        label.textColor = .white
        label.backgroundColor = .init(named: "red_FE95B4")
        label.textAlignment = .center
        label.isHidden = true
        return label
    }()
    
    lazy var nameLabel: UILabel = {
        let label = UILabel()
        label.font = .wn_font(name: .bold, size: 14)
        label.textColor = .black
        return label
    }()
    
    lazy var authorLabel: UILabel = {
        let label = UILabel()
        label.font = .wn_font(name: .bold, size: 12)
        label.textColor = .init(named: "gray_999999")
        return label
    }()
    
    lazy var desLabel: UILabel = {
        let label = UILabel()
        label.font = .wn_font(name: .bold, size: 12)
        label.textColor = .init(named: "gray_999999")
        label.numberOfLines = 2
        return label
    }()
    
    lazy var lineView: UIView = {
        let view = UIView()
        view.backgroundColor = .init(named: "gray_D0D0D0")
        return view
    }()

    var model: BookDetailModel? {
        didSet {
            if let m = model {
                bookImage.wn_setupImg(m.coverUrl, placeHolder: "placeholder_cover_ver")
                nameLabel.text = m.name
                authorLabel.text = m.authorname
                desLabel.text = m.des
            }
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(bookImage)
        bookImage.addSubview(disLabel)
        addSubview(nameLabel)
        addSubview(authorLabel)
        addSubview(desLabel)
        addSubview(lineView)
        bookImage.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalTo(12)
            make.size.equalTo(CGSize(width: scaleWidth(80), height: scaleWidth(116)))
        }
        disLabel.snp.makeConstraints { (make) in
            make.top.equalTo(5)
            make.right.equalTo(-5)
            make.height.equalTo(14)
            make.width.equalTo(0)
        }
        nameLabel.snp.makeConstraints { (make) in
            make.left.equalTo(bookImage.snp.right).offset(12)
            make.top.equalTo(bookImage.snp.top).offset(10)
            make.right.equalTo(-12)
        }
        authorLabel.snp.makeConstraints { (make) in
            make.left.equalTo(nameLabel.snp.left)
            make.top.equalTo(nameLabel.snp.bottom).offset(10)
            make.right.equalTo(-12)
        }
        desLabel.snp.makeConstraints { (make) in
            make.left.equalTo(nameLabel.snp.left)
            make.top.equalTo(authorLabel.snp.bottom).offset(12)
            make.right.equalTo(-12)
        }
        lineView.snp.makeConstraints { (make) in
            make.left.equalTo(12)
            make.bottom.right.equalTo(0)
            make.height.equalTo(0.5)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
